<template>
  <!-- 个人名片设置展示信息页面 -->
  <view class="main">
    <view class="xian"></view>
    <view class="content">
      <view class="xiding">
        <view class="tab">
          <view
            :class="[current == index ? 'isactive' : '']"
            v-for="(item, index) in tabList"
            @tap="qiehuan(index)"
          >
            {{ item }}
          </view>
        </view>
        <text class="active" :style="{ 'margin-left': tabMargin }"></text>
      </view>
      <swiper
        class="swiper"
        :style="{ height: '100vh' }"
        :indicator-dots="indicatorDots"
        :autoplay="autoplay"
        :interval="interval"
        :duration="duration"
        :current="swiperIndex"
        @change="change"
      >
        <swiper-item>
          <view class="content1">
            <view class="left">显示全部企业号</view>
            <view class="right">
              <switch :checked="qyhisAll" @tap="qyhShezhiAll" />
            </view>
          </view>
          <view class="text">
            <view class="list" v-for="(item, index) in qyhData" :key="index">
              <view class="left">
                <text class="dian"></text>
                <text>{{ item.orgName }}</text>
              </view>
              <view class="right">
                <switch
                  :checked="item.status == 1 ? true : false"
                  @change="qyhChange"
                  @tap="qyhShezhiOne(item.id)"
                />
              </view>
            </view>
          </view>
        </swiper-item>
        <swiper-item>
          <view class="content1">
            <view class="left">显示全部商协会号</view>
            <view class="right">
              <switch :checked="sxhisAll" @tap="sxhShezhiAll" />
            </view>
          </view>
          <view class="text">
            <view class="list" v-for="(item, index) in sxhData" :key="index">
              <view class="left">
                <text class="dian"></text>
                <text>{{ item.orgName }}</text>
              </view>
              <view class="right">
                <switch
                  :checked="item.status == 1 ? true : false"
                  @change="sxhChange"
                  @tap="sxhShezhiOne(item.id)"
                />
              </view>
            </view>
          </view>
        </swiper-item>
        <swiper-item>
          <view class="content1">
            <view class="left">显示全部圈子</view>
            <view class="right">
              <switch :checked="qzisAll" @tap="qzShezhiAll" />
            </view>
          </view>
          <view class="text">
            <view class="list" v-for="(item, index) in qzData" :key="index">
              <view class="left">
                <text class="dian"></text>
                <text>{{ item.orgName }}</text>
              </view>
              <view class="right">
                <switch
                  :checked="item.status == 1 ? true : false"
                  @change="qzChange"
                  @tap="qzShezhiOne(item.id)"
                />
              </view>
            </view>
          </view>
        </swiper-item>
      </swiper>
    </view>
  </view>
</template>

<script>
import request from "../../utils/request.js";
export default {
  data() {
    return {
      cardData: {},
      qyhData: [],
      sxhData: [],
      qzData: [],
      swiperIndex: "",
      dongHeight: "400rpx",
      tabMargin: "85rpx",
      current: "",
      id: "",
      userid: "",
      indicatorDots: false,
      autoplay: false,
      qzisReward: "",
      qzisAll: false,
      qyhisReward: "",
      qyhisAll: false,
      sxhisReward: "",
      sxhisAll: false,
      interval: 2000,
      duration: 500,
      tabList: ["企业号", "商协会号", "圈子"],
    };
  },
  onLoad() {
    this.qzDataList();
    this.qyhDataList();
    this.sxhDataList();
  },
  methods: {
    qzChange(e) {
      //圈子是否显示
      if (e.detail.value) {
        this.qzisReward = 1;
      } else {
        this.qzisReward = 0;
      }
      console.log(e);
    },
    qyhChange(e) {
      //圈子是否显示
      if (e.detail.value) {
        this.qyhisReward = 1;
      } else {
        this.qyhisReward = 0;
      }
      console.log(e);
    },
    sxhChange(e) {
      //圈子是否显示
      if (e.detail.value) {
        this.sxhisReward = 1;
      } else {
        this.sxhisReward = 0;
      }
      console.log(e);
    },
    qiehuan(index) {
      this.swiperIndex = index;
      if (index == 0) {
        this.tabMargin = index * 270 + 85 + "rpx";
      } else if (index == 1) {
        this.tabMargin = index * 270 + 85 + "rpx";
      } else if (index == 2) {
        this.tabMargin = index * 260 + 80 + "rpx";
      }
      if (index == 0 && this.qyhData.length > 0) {
        this.dongHeight = this.qyhData.length * 208 + "rpx";
      } else if (index == 1 && this.sxhData.length > 0) {
        this.dongHeight = this.sxhData.length * 208 + "rpx";
      } else if (index == 2 && this.qzData.length > 0) {
        this.dongHeight = this.qzData.length * 208 + "rpx";
      } else {
        this.dongHeight = "400rpx";
      }
    },
    change(e) {
      this.current = e.detail.current;
      if (e.detail.current == 0) {
        this.tabMargin = e.detail.current * 270 + 85 + "rpx";
      } else if (e.detail.current == 1) {
        this.tabMargin = e.detail.current * 270 + 85 + "rpx";
      } else if (e.detail.current == 2) {
        this.tabMargin = e.detail.current * 260 + 80 + "rpx";
      }
      if (e.detail.current == 0 && this.qyhData.length > 0) {
        this.dongHeight = this.qyhData.length * 208 + "rpx";
      } else if (e.detail.current == 1 && this.sxhData.length > 0) {
        this.dongHeight = this.sxhData.length * 208 + "rpx";
      } else if (e.detail.current == 2 && this.qzData.length > 0) {
        this.dongHeight = this.qzData.length * 208 + "rpx";
      } else {
        this.dongHeight = "400rpx";
      }
    },
    qzDataList() {
      let token = uni.getStorageSync("token");
      const that = this;
      if (!token) {
        uni.showToast({
          title: "请授权登录再操作！",
          duration: 2000,
          icon: "none",
        });
        setTimeout(() => {
          uni.navigateTo({
            url: "/pages/index/index",
          });
        }, 2000);
      } else {
        request({
          url: "app/org/getUserPrivacyOrg?uid=0b92c45a14b611e981b5fa163e4d6bc3",
          method: "POST",
          header: {
            "content-type": "application/json;charset=UTF-8",
            "api-client": "72e0fee8172411ea995200163e05ff66",
            "api-version": "1.3.3",
            "Source-Type": 7,
            token: token,
          },
          data: {
            type: 3,
          },
        }).then((res) => {
          if (res.data.code == 200) {
            that.qzData = res.data.data;
            that.qzisAll = res.data.data.every((item) => {
              return item.status == 1;
            });
          } else if (res.data.code == 401) {
            uni.showToast({
              title: "登录失效，请重新授权登录！",
              duration: 2000,
              icon: "none",
            });
            setTimeout(() => {
              uni.navigateTo({
                url: "/pages/index/index",
              });
            }, 2000);
          } else {
            uni.showToast({
              title: res.data.msg,
              duration: 2000,
              icon: "none",
            });
          }
        });
      }
    },
    qzShezhiOne(id) {
      let token = uni.getStorageSync("token");
      const that = this;
      if (!token) {
        uni.showToast({
          title: "请授权登录再操作！",
          duration: 2000,
          icon: "none",
        });
        setTimeout(() => {
          uni.navigateTo({
            url: "/pages/index/index",
          });
        }, 2000);
      } else {
        request({
          url:
            "app/programUserPrivacy/updatePrivacyShowOrg?uid=0b92c45a14b611e981b5fa163e4d6bc3",
          method: "POST",
          header: {
            "content-type": "application/json;charset=UTF-8",
            "api-client": "72e0fee8172411ea995200163e05ff66",
            "api-version": "1.3.3",
            "Source-Type": 7,
            token: token,
          },
          data: {
            orgId: id,
            status: this.qzisReward,
            updateFlag: 0,
          },
        }).then((res) => {
          if (res.data.code == 200) {
            that.qzDataList();
          } else if (res.data.code == 401) {
            uni.showToast({
              title: "登录失效，请重新授权登录！",
              duration: 2000,
              icon: "none",
            });
            setTimeout(() => {
              uni.navigateTo({
                url: "/pages/index/index",
              });
            }, 2000);
          } else {
            uni.showToast({
              title: res.data.msg,
              duration: 2000,
              icon: "none",
            });
          }
        });
      }
    },
    qzShezhiAll() {
      let token = uni.getStorageSync("token");
      const that = this;
      if (!token) {
        uni.showToast({
          title: "请授权登录再操作！",
          duration: 2000,
          icon: "none",
        });
        setTimeout(() => {
          uni.navigateTo({
            url: "/pages/index/index",
          });
        }, 2000);
      } else {
        request({
          url: "app/programUserPrivacy/updatePrivacyCategoryShowOrg",
          method: "POST",
          header: {
            "content-type": "application/json;charset=UTF-8",
            "api-client": "72e0fee8172411ea995200163e05ff66",
            "api-version": "1.3.3",
            "Source-Type": 7,
            token: token,
          },
          data: {
            updateFlag: 1,
            allFlag: this.qzisAll == true ? 0 : 1, //1开启
            type: 3,
          },
        }).then((res) => {
          if (res.data.code == 200) {
            that.qzDataList();
          } else if (res.data.code == 401) {
            uni.showToast({
              title: "登录失效，请重新授权登录！",
              duration: 2000,
              icon: "none",
            });
            setTimeout(() => {
              uni.navigateTo({
                url: "/pages/index/index",
              });
            }, 2000);
          } else {
            uni.showToast({
              title: res.data.msg,
              duration: 2000,
              icon: "none",
            });
          }
        });
      }
    },
    qyhDataList() {
      let token = uni.getStorageSync("token");
      const that = this;
      if (!token) {
        uni.showToast({
          title: "请授权登录再操作！",
          duration: 2000,
          icon: "none",
        });
        setTimeout(() => {
          uni.navigateTo({
            url: "/pages/index/index",
          });
        }, 2000);
      } else {
        request({
          url: "app/org/getUserPrivacyOrg?uid=0b92c45a14b611e981b5fa163e4d6bc3",
          method: "POST",
          header: {
            "content-type": "application/json;charset=UTF-8",
            "api-client": "72e0fee8172411ea995200163e05ff66",
            "api-version": "1.3.3",
            "Source-Type": 7,
            token: token,
          },
          data: {
            type: 1,
          },
        }).then((res) => {
          if (res.data.code == 200) {
            that.qyhData = res.data.data;
            that.qyhisAll = res.data.data.every((item) => {
              return item.status == 1;
            });
          } else if (res.data.code == 401) {
            uni.showToast({
              title: "登录失效，请重新授权登录！",
              duration: 2000,
              icon: "none",
            });
            setTimeout(() => {
              uni.navigateTo({
                url: "/pages/index/index",
              });
            }, 2000);
          } else {
            uni.showToast({
              title: res.data.msg,
              duration: 2000,
              icon: "none",
            });
          }
        });
      }
    },
    qyhShezhiOne(id) {
      let token = uni.getStorageSync("token");
      const that = this;
      if (!token) {
        uni.showToast({
          title: "请授权登录再操作！",
          duration: 2000,
          icon: "none",
        });
        setTimeout(() => {
          uni.navigateTo({
            url: "/pages/index/index",
          });
        }, 2000);
      } else {
        request({
          url:
            "app/programUserPrivacy/updatePrivacyShowOrg?uid=0b92c45a14b611e981b5fa163e4d6bc3",
          method: "POST",
          header: {
            "content-type": "application/json;charset=UTF-8",
            "api-client": "72e0fee8172411ea995200163e05ff66",
            "api-version": "1.3.3",
            "Source-Type": 7,
            token: token,
          },
          data: {
            orgId: id,
            status: this.qyhisReward,
            updateFlag: 0,
          },
        }).then((res) => {
          if (res.data.code == 200) {
            that.qyhDataList();
          } else if (res.data.code == 401) {
            uni.showToast({
              title: "登录失效，请重新授权登录！",
              duration: 2000,
              icon: "none",
            });
            setTimeout(() => {
              uni.navigateTo({
                url: "/pages/index/index",
              });
            }, 2000);
          } else {
            uni.showToast({
              title: res.data.msg,
              duration: 2000,
              icon: "none",
            });
          }
        });
      }
    },
    qyhShezhiAll() {
      let token = uni.getStorageSync("token");
      const that = this;
      if (!token) {
        uni.showToast({
          title: "请授权登录再操作！",
          duration: 2000,
          icon: "none",
        });
        setTimeout(() => {
          uni.navigateTo({
            url: "/pages/index/index",
          });
        }, 2000);
      } else {
        request({
          url: "app/programUserPrivacy/updatePrivacyCategoryShowOrg",
          method: "POST",
          header: {
            "content-type": "application/json;charset=UTF-8",
            "api-client": "72e0fee8172411ea995200163e05ff66",
            "api-version": "1.3.3",
            "Source-Type": 7,
            token: token,
          },
          data: {
            updateFlag: 1,
            allFlag: this.qyhisAll == true ? 0 : 1, //1开启
            type: 1,
          },
        }).then((res) => {
          if (res.data.code == 200) {
            that.qyhDataList();
          } else if (res.data.code == 401) {
            uni.showToast({
              title: "登录失效，请重新授权登录！",
              duration: 2000,
              icon: "none",
            });
            setTimeout(() => {
              uni.navigateTo({
                url: "/pages/index/index",
              });
            }, 2000);
          } else {
            uni.showToast({
              title: res.data.msg,
              duration: 2000,
              icon: "none",
            });
          }
        });
      }
    },
    sxhDataList() {
      let token = uni.getStorageSync("token");
      const that = this;
      if (!token) {
        uni.showToast({
          title: "请授权登录再操作！",
          duration: 2000,
          icon: "none",
        });
        setTimeout(() => {
          uni.navigateTo({
            url: "/pages/index/index",
          });
        }, 2000);
      } else {
        request({
          url: "app/org/getUserPrivacyOrg?uid=0b92c45a14b611e981b5fa163e4d6bc3",
          method: "POST",
          header: {
            "content-type": "application/json;charset=UTF-8",
            "api-client": "72e0fee8172411ea995200163e05ff66",
            "api-version": "1.3.3",
            "Source-Type": 7,
            token: token,
          },
          data: {
            type: 2,
          },
        }).then((res) => {
          if (res.data.code == 200) {
            that.sxhData = res.data.data;
            that.sxhisAll = res.data.data.every((item) => {
              return item.status == 1;
            });
          } else if (res.data.code == 401) {
            uni.showToast({
              title: "登录失效，请重新授权登录！",
              duration: 2000,
              icon: "none",
            });
            setTimeout(() => {
              uni.navigateTo({
                url: "/pages/index/index",
              });
            }, 2000);
          } else {
            uni.showToast({
              title: res.data.msg,
              duration: 2000,
              icon: "none",
            });
          }
        });
      }
    },
    sxhShezhiOne(id) {
      let token = uni.getStorageSync("token");
      const that = this;
      if (!token) {
        uni.showToast({
          title: "请授权登录再操作！",
          duration: 2000,
          icon: "none",
        });
        setTimeout(() => {
          uni.navigateTo({
            url: "/pages/index/index",
          });
        }, 2000);
      } else {
        request({
          url:
            "app/programUserPrivacy/updatePrivacyShowOrg?uid=0b92c45a14b611e981b5fa163e4d6bc3",
          method: "POST",
          header: {
            "content-type": "application/json;charset=UTF-8",
            "api-client": "72e0fee8172411ea995200163e05ff66",
            "api-version": "1.3.3",
            "Source-Type": 7,
            token: token,
          },
          data: {
            orgId: id,
            status: this.sxhisReward,
            updateFlag: 0,
          },
        }).then((res) => {
          if (res.data.code == 200) {
            that.sxhDataList();
          } else if (res.data.code == 401) {
            uni.showToast({
              title: "登录失效，请重新授权登录！",
              duration: 2000,
              icon: "none",
            });
            setTimeout(() => {
              uni.navigateTo({
                url: "/pages/index/index",
              });
            }, 2000);
          } else {
            uni.showToast({
              title: res.data.msg,
              duration: 2000,
              icon: "none",
            });
          }
        });
      }
    },
    sxhShezhiAll() {
      let token = uni.getStorageSync("token");
      const that = this;
      if (!token) {
        uni.showToast({
          title: "请授权登录再操作！",
          duration: 2000,
          icon: "none",
        });
        setTimeout(() => {
          uni.navigateTo({
            url: "/pages/index/index",
          });
        }, 2000);
      } else {
        request({
          url: "app/programUserPrivacy/updatePrivacyCategoryShowOrg",
          method: "POST",
          header: {
            "content-type": "application/json;charset=UTF-8",
            "api-client": "72e0fee8172411ea995200163e05ff66",
            "api-version": "1.3.3",
            "Source-Type": 7,
            token: token,
          },
          data: {
            updateFlag: 1,
            allFlag: this.sxhisAll == true ? 0 : 1, //1开启
            type: 2,
          },
        }).then((res) => {
          if (res.data.code == 200) {
            that.sxhDataList();
          } else if (res.data.code == 401) {
            uni.showToast({
              title: "登录失效，请重新授权登录！",
              duration: 2000,
              icon: "none",
            });
            setTimeout(() => {
              uni.navigateTo({
                url: "/pages/index/index",
              });
            }, 2000);
          } else {
            uni.showToast({
              title: res.data.msg,
              duration: 2000,
              icon: "none",
            });
          }
        });
      }
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  height: 100vh;
  background-color: #f8f8fa;
  .xian {
    height: 1rpx;
    background-color: #dddddd;
  }
  .content {
    .active {
      display: block;
      width: 50rpx;
      height: 4rpx;
      background-color: #0074d9;
    }
    .content1 {
      padding: 0 32rpx;
      height: 100rpx;
      display: flex;
      justify-content: space-between;
      align-items: center;
      background-color: #ffffff;
      margin-top: 20rpx;
      .left {
        font-size: 34rpx;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #333333;
      }
    }
  }
  .text {
    padding: 0 32rpx;
    background-color: #ffffff;
    margin-top: 20rpx;
    .list {
      height: 100rpx;
      display: flex;
      align-items: center;
      justify-content: space-between;
      border-bottom: 1rpx solid #dddddd;
      &:last-child {
        border: none;
      }
      .left {
        display: flex;
        align-items: center;
        .dian {
          width: 15rpx;
          height: 15rpx;
          background-color: #0074d9;
          border-radius: 50%;
          margin-right: 15rpx;
        }
      }
    }
  }
  .xiding {
    position: -webkit-sticky;
    position: sticky;
    top: var(--window-top);
    z-index: 99;
    background-color: #ffffff;
    padding: 15rpx;
  }
  .tab {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 60rpx;
    margin-bottom: 15rpx;
    view {
      color: #333333;
      font-size: 34rpx;
      font-weight: 500;
    }
    .isactive {
      font-size: 35rpx;
      font-weight: bold;
    }
  }
}
</style>
